package view;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.*;
import javax.swing.plaf.basic.*;
import javax.swing.table.TableColumnModel;

import controller.ReptielController;
import controller.VogelController;
import controller.Zoogdiercontroller;
import model.*;
import Lijsten.*;
import TabelModels.DierentuinTabelModel;

public class StartUp_view extends JFrame {

	private JPanel panel1 = new JPanel();
	private JTabbedPane tabPane = new JTabbedPane();
	private JPanel tabpanel1 = new JPanel();
	private JLabel label1 = new JLabel();
	private Zoogdiercontroller zc = new Zoogdiercontroller();
	private ReptielController rc = new ReptielController();
	private VogelController vc = new VogelController();

	public JTable tabel = new JTable();
	public JTable tabel2 = new JTable();
	public JTable tabel3 = new JTable();

	private JPanel tabelmammels = new JPanel();
	private JPanel tabelreptils = new JPanel();
	private JPanel tabelbirds = new JPanel();
	
	private static StartUp_view instance;
	

	public static StartUp_view getInstance(){
		if(instance == null){
			instance = new StartUp_view();
		}
		return instance;
	}
	
	private StartUp_view() {
		tabPane.setUI(new BasicTabbedPaneUI() {
			protected int calculateTabWidth(int tabPlacement, int tabIndex,
					FontMetrics metrics) {
				return 125; // the width of the tab
			}
		});

		// #frame
		setVisible(true);
		setSize(500, 400);
		setDefaultCloseOperation(StartUp_view.EXIT_ON_CLOSE);

		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height
				/ 2 - this.getSize().height / 2);

		// #panel1
		panel1.setVisible(true);
		panel1.setLayout(null);
		panel1.setSize(400, 400);
		panel1.setBackground(Color.white);

		// #tabb1
		// #tabel
		tabel = new JTable(new DierentuinTabelModel("Zoogdier"));
		tabel2 = new JTable(new DierentuinTabelModel("Reptiel"));
		tabel3 = new JTable(new DierentuinTabelModel("Vogel"));
		
		
		JScrollPane scroll2 = new JScrollPane(tabel2);
		scroll2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		scroll2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		scroll2.setBounds(0, 0, tabelreptils.getWidth(),
				tabelreptils.getHeight());
		scroll2.setVisible(true);
		tabel2.setPreferredScrollableViewportSize(new Dimension(467, getHeight()));

		tabelreptils.add(scroll2);
		
		JScrollPane scroll3 = new JScrollPane(tabel3);
		scroll3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		scroll3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		scroll3.setBounds(0, 0, tabelbirds.getWidth(),
				tabelbirds.getHeight());
		scroll3.setVisible(true);
		tabel3.setPreferredScrollableViewportSize(new Dimension(467, getHeight()));

		tabelbirds.add(scroll3);
	
		
		JScrollPane scroll = new JScrollPane(tabel);
		scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		scroll.setBounds(0, 0, tabelmammels.getWidth(),
				tabelmammels.getHeight());
		scroll.setVisible(true);
		tabel.setPreferredScrollableViewportSize(new Dimension(467, getHeight()));

		tabelmammels.add(scroll);
		

		JPanel jp1 = new JPanel();
		jp1.setVisible(true);
		tabPane.setVisible(true);

		ImageIcon tab1Icon = new ImageIcon(this.getClass().getResource(
				"/img/zoogdier.png"));

		JLabel label1 = new JLabel();
		label1.setText("This is Tab 1");

		jp1.add(tabelmammels);

		tabPane.addTab("Zoogdieren", tab1Icon, jp1);

		add(tabPane);

		// #tabb2
		JPanel jp2 = new JPanel();
		jp2.setVisible(true);

		ImageIcon tab2Icon = new ImageIcon(this.getClass().getResource(
				"/img/reptiel.png"));

		JLabel label2 = new JLabel();
		label2.setText("This is a Second label");
		jp2.add(tabelreptils);

		tabPane.addTab("Reptielen", tab2Icon, jp2);

		// #tabb3
		JPanel jp3 = new JPanel();
		jp3.setVisible(true);

		ImageIcon tab3Icon = new ImageIcon(this.getClass().getResource(
				"/img/vogel.png"));

		JLabel label3 = new JLabel();
		label3.setText("This is a third label");
		jp3.add(tabelbirds);

		tabPane.addTab("Vogels", tab3Icon, jp3);
		
		
		tabel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					zc.tabel1();
				}
			}
		});
		
		tabel2.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					rc.tabel2();
				}
			}
		});
		
		tabel3.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					vc.tabel3();
				}
			}
		});
		
	}
}
